package com.ruoyi.system.api.service.impl;

import cn.jiguang.common.resp.APIConnectionException;
import cn.jiguang.common.resp.APIRequestException;
import cn.jpush.api.push.PushResult;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;
import com.ruoyi.common.config.Global;
import com.ruoyi.common.config.JPushConfig;
import com.ruoyi.common.config.PushConfig;
import com.ruoyi.common.jpush.JPushClientUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.api.ResponseWithData;
import com.ruoyi.system.api.domain.*;
import com.ruoyi.system.api.mapper.*;
import com.ruoyi.system.api.service.IInterfaceOperationLogService;
import com.ruoyi.system.api.service.LocationService;
import com.ruoyi.system.api.service.OnlineServiceService;
import com.ruoyi.system.api.service.PokeRequestServe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @ClassName SparePartsServiceImpl
 * @Description: TODO
 * @Author wlf
 * @Date 2020/3/2
 * @Version V1.0
 **/
@Service
public class OnlineServiceServiceImpl implements OnlineServiceService {

    private static final Logger log = LoggerFactory.getLogger(OnlineServiceServiceImpl.class);

    /**
     * 配置文件
     */
    @Autowired
    private Global global;

    @Autowired
    private PokeRequestServe pokeRequestServe;

    /** 用户表 */
    @Autowired
    private UserMapper userMapper;

    /** 接口调用日志 */
    @Autowired
    private IInterfaceOperationLogService iInterfaceOperationLogService;

    @Autowired
    private ServiceNoticeMapper serviceNoticeMapper;

    @Autowired
    private ServiceInstrumentMapper serviceInstrumentMapper;

    @Autowired
    private InstrumentInfoMapper instrumentInfoMapper;

    @Autowired
    private LocationService locationService;

    @Autowired
    private ServicePartMapper servicePartMapper;

    @Autowired
    private ServiceDetailsMapper serviceDetailsMapper;

    @Autowired
    private PlanDetailsMapper planDetailsMapper;

    @Autowired
    private JPushConfig jPushConfig;

    @Autowired
    private JpushLogMapper jpushLogMapper;

    @Override
    public ResponseWithData<?> createOrder(Order params) throws Exception{
        // 创建当前时间戳
        Long timeStamp = System.currentTimeMillis();
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("createOrder.asmx/createOrderhandle").toString();
        String postParam = pokeRequestServe.spellPrams(params);
        Map<String, String> map = pokeRequestServe.transPostJD(url.toString(), "建单申请", "createOrderhandle", postParam);
        Integer code = Integer.parseInt(map.get("code"));
        String Customer_service_id = ""; //cc端成功是返回的服务通知单号
        if (code== 200) {
            String body = map.get("responseBody");
            JSONObject resObj = JSON.parseObject(body);
            // 获取接口返回的服务通知号
            //if (resObj.getInteger("status") == 2) {
//                // status == 1 接口返回成功
//                JSONArray record = resObj.getJSONArray("record");
//                if (null != record && record.size() > 0) {
//                    JSONObject arr0 = record.getJSONObject(0);
//                    Customer_service_id = arr0.getString("Customer_service_id");
//                }
              return new ResponseWithData().success(body).msg("success").code(200);
          //  }
//            // 同步服务通知数据
//            if (StringUtils.isNotEmpty(Customer_service_id)) {
//                getNotificationInfo(params, timeStamp); // 2.8同步FSE服务信息接口
//            }
        } else {
            return new ResponseWithData().error().msg(map.get("msg")).code(code);
        }
    }

    /**
     * 2.8同步FSE服务信息接口
     */
    private void getNotificationInfo(Order params, Long timeStamp)  throws Exception{
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("syncServiceData.asmx/GetNotificationInfo");

        String postParam = "last_sync_time=" + timeStamp + "&enginner_id=" + params.getEnginner_id();
        Map<String, String> resultMap = pokeRequestServe.transPostJD(url.toString(), "同步FSE服务信息接口", "GetNotificationInfo", postParam);
        Integer code = Integer.parseInt(resultMap.get("code"));
        if (code== 200) {
            // 调用成功
            String body = resultMap.get("responseBody");
            JSONObject obj = JSON.parseObject(body);
            if("1".equals(obj.getString("status"))){

                /** 获取CC端 */
                JSONArray jsonArray = obj.getJSONArray("record");
                if(jsonArray!=null && jsonArray.size()>0){
                    for (int i=0;i<jsonArray.size();i++){

                        ServiceNotice serviceNotice = new ServiceNotice();
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

                        JSONObject jsonObject = jsonArray.getJSONObject(i);
                        // Service号
                        String service_no = jsonObject.getString("service_no");
                        serviceNotice.setServiceNo(service_no);

                        /** 通过服务号验证数据库中是否存在 */
                        List<ServiceNotice> serviceNoticeList = serviceNoticeMapper.selectServiceNoticeList(serviceNotice);

                        // TODO 指派工程师 接口文档中有 返回的接口没有
                        String Fse = params.getEnginner_id();
                        serviceNotice.setFse(Fse);

                        // Teamleader
                        String teamleader = params.getTeamleaderId();
                        serviceNotice.setTeamleaderId(teamleader);

                        if(serviceNoticeList!=null && serviceNoticeList.size()>0){
                            serviceNotice.setId(serviceNoticeList.get(0).getId());
                        }else{
//                            serviceNotice.setAppState(1L);
                            serviceNotice.setAppState(1L); //1：待派单；2：服务中
                            serviceNotice.setRecordTime(new Date());
                            serviceNoticeMapper.insertServiceNotice(serviceNotice);



                            // 验证服务单是已经指派过的
                            if(org.apache.commons.lang3.StringUtils.isNotEmpty(Fse)){
                                String[] Fses = Fse.split(",");
                                for (String fse : Fses) {
                                    // TODO 有指派的人生成派单数据
                                    if(org.apache.commons.lang3.StringUtils.isNotEmpty(fse)){

                                        User user = new User();
                                        user.setEnginnerId(Long.parseLong(fse));
                                        List<User> users = userMapper.selectUserList(user);
                                        PlanDetails planDetails = new PlanDetails();
                                        ServiceDetails serviceDetails = new ServiceDetails();
                                        if(users!=null && users.size()>0){
                                            planDetails.setFseName(users.get(0).getName());
                                            serviceDetails.setFseName(users.get(0).getName());

                                            planDetails.setServiceNoticeId(serviceNotice.getId());
                                            planDetails.setServiceNo(service_no);
                                            planDetails.setFseId(fse);
                                            planDetails.setIsAccept("2"); //是否接受 0拒绝 1接受 2待处理
                                            planDetails.setState("0"); //0待接受，1已接受
//                                            planDetails.setAcceptTime(new Date(timeStamp)); //需求变更，接受时存入
                                            planDetails.setDelFlag("0");
                                            planDetails.setCreateTime(new Date());
                                            // 需求变更，不存时间
//                                            planDetails.setEstimatedVisitingTime(params.getEstimatedVisitingTime()); //预计上门时
//                                            planDetails.setEstimatedWorkingHours(params.getEstimatedWorkingHours()); //预计工时
//                                            planDetails.setEstimatedDepartureTime(params.getEstimatedDepartureTime()); //预计离开时间
                                            planDetailsMapper.insertStPlanDetails(planDetails);

                                            serviceDetails.setServiceNoticeId(serviceNotice.getId());
                                            serviceDetails.setServiceNo(service_no);
                                            serviceDetails.setFseId(fse);
                                            serviceDetails.setState(0L); //0待接受，1已接受
                                            serviceDetails.setDelFlag("0"); //0代表存在 2代表删除
                                            serviceDetails.setCreateTime(new Date());
                                            serviceDetailsMapper.insertServiceDetails(serviceDetails);

                                        }

                                    }
                                }
                            }
                        }

                        // 联系人
                        String contact = jsonObject.getString("contact");
                        serviceNotice.setContact(contact);

                        // 用户名称
                        String customer_name = jsonObject.getString("customer_name");
                        serviceNotice.setCustomerName(customer_name);

                        // 用户英文名称
                        String customer_enname = jsonObject.getString("customer_enname");
                        serviceNotice.setCustomerEnname(customer_enname);

                        // 电话
                        String telephone = jsonObject.getString("telephone");
                        serviceNotice.setTelephone(telephone);

                        // 客户类型
                        String enginner_type = jsonObject.getString("enginner_type");
                        serviceNotice.setEnginnerType(enginner_type);

                        // 手机
                        String mobile = jsonObject.getString("mobile");
                        serviceNotice.setMobile(mobile);

                        // 电子邮件
                        String email = jsonObject.getString("email");
                        serviceNotice.setEmail(email);

                        // 省份
                        String province = jsonObject.getString("province");
                        serviceNotice.setProvince(province);

                        // 服务合同
                        String service_contract = jsonObject.getString("service_contract")==null?"":jsonObject.getString("service_contract");
                        serviceNotice.setServiceContract(service_contract);

                        // 城市
                        String city = jsonObject.getString("city");
                        serviceNotice.setCity(city);

                        // 希望服务时间
                        String hope_business_hours = jsonObject.getString("hope_business_hours");
                        if(org.apache.commons.lang3.StringUtils.isNotEmpty(hope_business_hours)){
                            if(hope_business_hours.length()==10){
                                hope_business_hours += " 00:00:00";
                            }
                            serviceNotice.setHopeBusinessHours(sdf.parse(hope_business_hours));
                        }

                        // 上门地址
                        String home_address = jsonObject.getString("home_address");
                        serviceNotice.setHomeAddress(home_address);

                        // 完备日期
                        String MaturityDate = jsonObject.getString("MaturityDate");
                        serviceNotice.setMaturityDate(sdf.parse(MaturityDate));

                        // 服务类型
                        String service_type = jsonObject.getString("service_type");
                        serviceNotice.setServiceType(service_type);

                        // 子服务类型
                        String sub_service_type = jsonObject.getString("sub_service_type")==null?"":jsonObject.getString("sub_service_type");
                        serviceNotice.setSubServiceType(sub_service_type);

                        // 服务级别
                        String service_level = jsonObject.getString("service_level");
                        serviceNotice.setServiceLevel(service_level);

                        // 服务状态
                        String service_status = jsonObject.getString("service_status");
                        serviceNotice.setServiceStatus(service_status);

                        // 安装准备确认单
                        String install_confirm_sheet = jsonObject.getString("install_confirm_sheet");
                        serviceNotice.setInstallConfirmSheet(install_confirm_sheet);

                        // 生成时间
                        String create_time = jsonObject.getString("create_time");
                        serviceNotice.setCreateTime(sdf.parse(create_time));

                        // 是否保内
                        String is_warranty = jsonObject.getString("is_warranty");
                        serviceNotice.setIsWarranty(is_warranty);

                        // 距离上次服务关闭时间
                        Long last_colse_service_time = jsonObject.getLong("last_colse_service_time");
                        if(last_colse_service_time!=null){
                            serviceNotice.setLastColseServiceTime(last_colse_service_time);
                        }

                        // 仪器最后服务关闭时间
                        String machine_last_service_colse_time = jsonObject.getString("machine_last_service_colse_time")==null?"":jsonObject.getString("machine_last_service_colse_time");
                        if(org.apache.commons.lang3.StringUtils.isNotEmpty(machine_last_service_colse_time)){
                            serviceNotice.setMachineLastServiceColseTime(sdf.parse(machine_last_service_colse_time));
                        }

                        // 派单人
                        String send_service = jsonObject.getString("send_service");
                        serviceNotice.setSendService(send_service);

                        // 派单时间
                        String Send_time = jsonObject.getString("Send_time")==null?"":jsonObject.getString("Send_time");
                        if(org.apache.commons.lang3.StringUtils.isNotEmpty(Send_time)){
                            if(Send_time.length()==10){
                                Send_time += " 00:00:00";
                            }
                            serviceNotice.setSendTime(sdf.parse(Send_time));
                        }

                        // 仪器信息 需要处理
                        String instrument_data = jsonObject.getString("instrument_data");

                        // TODO 解析仪器信息
                        JSONObject instrument_data_json = JSON.parseArray(instrument_data).getJSONObject(0);

                        /** 关联服务单的仪器表 */
                        ServiceInstrument serviceInstrument = new ServiceInstrument();
                        /** 仪器表 */
                        InstrumentInfo instrumentInfo = new InstrumentInfo();

                        // 仪器id
                        String instrument_id = instrument_data_json.getString("instrument_id");
                        serviceInstrument.setInstrumentId(instrument_id);
                        instrumentInfo.setInstrumentId(instrument_id);

                        serviceInstrument.setServiceNoticeId(serviceNotice.getId());
                        serviceInstrument.setServiceNo(serviceNotice.getServiceNo());

                        List<ServiceInstrument> serviceInstrumentList =  serviceInstrumentMapper.selectServiceInstrumentList(serviceInstrument);
                        List<InstrumentInfo> instrumentInfoList = instrumentInfoMapper.selectInstrumentInfoList(instrumentInfo);

                        // 仪器型号
                        String instrument_no = instrument_data_json.getString("instrument_no");
                        serviceInstrument.setInstrumentNo(instrument_no);

                        // 仪器序列号
                        String instrument_serial_number = instrument_data_json.getString("instrument_serial_number");
                        serviceInstrument.setInstrumentSerialNumber(instrument_serial_number);
                        instrumentInfo.setInstSn(instrument_serial_number);

                        // factory So
                        String factory_so = instrument_data_json.getString("factory_so");
                        serviceInstrument.setFactorySo(factory_so);

                        // 发货时间
                        String delivery_time = instrument_data_json.getString("delivery_time");
                        if(org.apache.commons.lang3.StringUtils.isNotEmpty(delivery_time)){
                            serviceInstrument.setDeliveryTime(sdf.parse(delivery_time));
                        }

                        // 保修开始时间
                        String guarantee_start_time = instrument_data_json.getString("guarantee_start_time");
                        if(org.apache.commons.lang3.StringUtils.isNotEmpty(guarantee_start_time)){
                            serviceInstrument.setGuaranteeStartTime(sdf.parse(guarantee_start_time));
                        }

                        // 保修结束时间
                        String guarantee_end_time = instrument_data_json.getString("guarantee_end_time");
                        if(org.apache.commons.lang3.StringUtils.isNotEmpty(guarantee_end_time)){
                            serviceInstrument.setGuaranteeEndTime(sdf.parse(guarantee_end_time));
                        }

                        // 合同
                        String contract = instrument_data_json.getString("contract");
                        serviceInstrument.setContract(contract);

                        // 备件
                        String part = instrument_data_json.getString("part");
                        serviceInstrument.setPart(part);

                        // SLA
                        String sla = instrument_data_json.getString("sla")==null?"":instrument_data_json.getString("sla");
                        serviceInstrument.setSla(sla);

                        // 备注
                        String instrument_remark = instrument_data_json.getString("instrument_remark");
                        serviceInstrument.setInstrumentRemark(instrument_remark);

                        // 仪器类型
                        String instrument_type = instrument_data_json.getString("instrument_type");
                        serviceInstrument.setInstrumentType(instrument_type);

                        // 仪器状态
                        String instrument_status = instrument_data_json.getString("instrument_status");
                        serviceInstrument.setInstrumentStatus(instrument_status);

                        // 状态备注
                        String Status_remark = instrument_data_json.getString("Status_remark");
                        serviceInstrument.setStatusRemark(Status_remark);

                        // Materialcode
                        String Materialcode = instrument_data_json.getString("Materialcode");
                        serviceInstrument.setMaterialcode(Materialcode);

                        // lifecycle
                        String lifecycle = instrument_data_json.getString("lifecycle");
                        serviceInstrument.setLifecycle(lifecycle);

                        // 品牌
                        String brand = instrument_data_json.getString("Brand");
                        serviceInstrument.setBrand(brand);

                        // 约定服务范围
                        String ServiceRange = instrument_data_json.getString("ServiceRange");
                        serviceInstrument.setServiceRange(ServiceRange);

                        // DEVI-BU
                        String divi_bu = instrument_data_json.getString("divi_bu");
                        serviceInstrument.setDiviBu(divi_bu);

                        // 安装地址
                        String InsAddress = instrument_data_json.getString("InsAddress");
                        instrumentInfo.setInstAddress(InsAddress);

                        // MD标识
                        String mdsign = instrument_data_json.getString("mdsign");
                        serviceInstrument.setMdsign(mdsign);

                        // 验收报告需求
                        String acceptrequest = instrument_data_json.getString("acceptrequest")==null?"":instrument_data_json.getString("acceptrequest");
                        serviceInstrument.setAcceptrequest(acceptrequest);


                        // TODO 备件信息 接口文档中有 返回的接口没有
                        String Part_data = jsonObject.getString("Part_data");
                        if(org.apache.commons.lang3.StringUtils.isNotEmpty(Part_data) && !"[]".equals(Part_data)){
                            JSONArray Part_data_jsonArray = JSON.parseArray(Part_data);

                            /** 先删除所有备件，然后在新增新的备件 */
                            ServicePart sp = new ServicePart();
                            sp.setServiceNoticeId(serviceNotice.getId());
                            servicePartMapper.deleteServicePart(sp);

                            for(int j=0; j<Part_data_jsonArray.size(); j++){
                                JSONObject Part_data_json = Part_data_jsonArray.getJSONObject(j);
                                ServicePart servicePart = new ServicePart();

                                servicePart.setServiceNoticeId(serviceNotice.getId());
                                servicePart.setServiceNo(serviceNotice.getServiceNo());

                                // 备件号
                                String Part_no = Part_data_json.getString("Part_no");
                                servicePart.setPartNo(Part_no);

                                // 备件名称
                                String Part_name = Part_data_json.getString("Part_name");
                                servicePart.setPartName(Part_name);

                                // 序列号
                                String serial_number = Part_data_json.getString("serial_number")==null?"":Part_data_json.getString("serial_number");
                                servicePart.setSerialNumber(serial_number);

                                // 借货单号
                                String Part_DebitNo = Part_data_json.getString("Part_DebitNo")==null?"":Part_data_json.getString("Part_DebitNo");
                                servicePart.setPartDebitNo(Part_DebitNo);

                                // 数量
                                String qty = Part_data_json.getString("qty")==null?"":Part_data_json.getString("qty");
                                servicePart.setQty(qty);

                                // 单价
                                String Price = Part_data_json.getString("Price")==null?"":Part_data_json.getString("Price");
                                servicePart.setPrice(Price);

                                // 总价
                                String TotalPrice = Part_data_json.getString("TotalPrice")==null?"":Part_data_json.getString("TotalPrice");
                                servicePart.setTotalPrice(TotalPrice);

                                // 备注
                                String remark = Part_data_json.getString("remark")==null?"":Part_data_json.getString("remark");
                                servicePart.setRemark(remark);

                                // partremark
                                String partremark = Part_data_json.getString("partremark")==null?"":Part_data_json.getString("partremark");
                                servicePart.setPartremark(partremark);

                                servicePart.setCreateTime(new Date());

                                // 保存服务单关联备件
                                servicePartMapper.insertServicePart(servicePart);

                            }

                        }

                        // 故障描述
                        String trouble_description = jsonObject.getString("trouble_description");
                        serviceNotice.setTroubleDescription(trouble_description);

                        // 备注
                        String remark = jsonObject.getString("remark");
                        serviceNotice.setRemark(remark);

                        // 客户VIP标识
                        String is_vip = jsonObject.getString("is_vip");
                        serviceNotice.setIsVip(is_vip);

                        // 接待人
                        String receiver= jsonObject.getString("receiver")==null?"":jsonObject.getString("receiver");
                        serviceNotice.setReceiver(receiver);

                        // 接待人手机
                        String receiver_mobile = jsonObject.getString("receiver_mobile")==null?"":jsonObject.getString("receiver_mobile");
                        serviceNotice.setReceiverMobile(receiver_mobile);

                        // 接待人邮箱
                        String receiver_email = jsonObject.getString("receiver_email")==null?"":jsonObject.getString("receiver_email");
                        serviceNotice.setReceiverEmail(receiver_email);

                        // 电脑厂家
                        String computer_Mfr = jsonObject.getString("computer_Mfr");
                        serviceNotice.setComputerMfr(computer_Mfr);

                        // 电脑型号
                        String model_number = jsonObject.getString("model_number");
                        serviceNotice.setModelNumber(model_number);

                        // 服务号
                        String service_number = jsonObject.getString("service_number");
                        serviceNotice.setServiceNumber(service_number);

                        // 操作系统
                        String software = jsonObject.getString("software");
                        serviceNotice.setSoftware(software);

                        // 选项软件
                        String option_software = jsonObject.getString("option_software");
                        serviceNotice.setOptionSoftware(option_software);

                        // 系统软件
                        String system_software = jsonObject.getString("system_software");
                        serviceNotice.setSystemSoftware(system_software);

                        // 培训名额
                        String train_quota = jsonObject.getString("train_quota");
                        serviceNotice.setTrainQuota(train_quota);

                        // 仪器类型
                        String producttype = jsonObject.getString("producttype")==null?"":jsonObject.getString("producttype");
                        serviceNotice.setProducttype(producttype);

                        // 合同信息
                        String contract_info = jsonObject.getString("contract_info");
                        serviceNotice.setContractInfo(contract_info);

                        // TODO arrive_time、service_enginner、appoint_time 字段接口文档中没有 返回值有

                        // 服务关闭时间
                        String close_time = jsonObject.getString("close_time");
                        if(org.apache.commons.lang3.StringUtils.isNotEmpty(close_time)){
                            if(close_time.length()==16){
                                close_time += ":00";
                            }
                            serviceNotice.setCloseTime(sdf.parse(close_time));
                        }

                        // 仪器安装时间
                        String installation_date = jsonObject.getString("installation_date");
                        if(org.apache.commons.lang3.StringUtils.isNotEmpty(installation_date)){
                            if(installation_date.length()==10){
                                installation_date += " 00:00:00";
                            }
                            serviceNotice.setInstallationDate(sdf.parse(installation_date));
                        }

                        // CFDA
                        String CFDA = jsonObject.getString("CFDA");
                        serviceNotice.setCfda(CFDA);

                        //1 ——CC操作APP不显示0——APP显示
                        String AppIsAccept = jsonObject.getString("AppIsAccept");
                        serviceNotice.setAppIsAccept(AppIsAccept);

                        /** 服务单主表 如果存在更新，如果不存在新增 */
//                        if(serviceNoticeList!=null && serviceNoticeList.size() > 0){
//                            serviceNotice.setId(serviceNoticeList.get(0).getId());
                        serviceNoticeMapper.updateServiceNotice(serviceNotice);
//                        }else {
//                            serviceNotice.setRecordTime(new Date());
//                            serviceNoticeMapper.insertServiceNotice(serviceNotice);
//                        }

                        /** 服务单仪器子表 */
                        if(serviceInstrumentList!=null && serviceInstrumentList.size()>0){
                            serviceInstrument.setId(serviceInstrumentList.get(0).getId());
                            serviceInstrument.setUpdateTime(new Date());
                            serviceInstrumentMapper.updateServiceInstrument(serviceInstrument);
                        }else{
                            serviceInstrument.setCreateTime(new Date());
                            serviceInstrumentMapper.insertServiceInstrument(serviceInstrument);
                        }

                        /** 仪器表 */
                        if(instrumentInfoList!=null && instrumentInfoList.size()>0){
                            instrumentInfo.setId(instrumentInfoList.get(0).getId());
                            instrumentInfo.setUpdateTime(new Date());
                            instrumentInfoMapper.updateInstrumentInfo(instrumentInfo);
                        }else {
                            /** 调用高德地理解析接口，根据地址解析经纬度 */
                            Map<String,String> map = locationService.AddressResolution(InsAddress,"");
                            if(map!=null&&map.size()==2){
                                instrumentInfo.setLongitude(Double.parseDouble(map.get("longitude")));
                                instrumentInfo.setLatitude(Double.parseDouble(map.get("latitude")));
                            }

                            instrumentInfo.setCreateTime(new Date());
                            instrumentInfoMapper.insertInstrumentInfo(instrumentInfo);
                        }

                    }
//                    return new ResponseWithData().success().msg("同步成功").code(200);
                }
            }
        } else {
            // 调用失败
        }
    }

    @Override
    public ResponseWithData<?> submitCallRecordInfo(CallRecord params) throws Exception{
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("submitCallRecordInfo.asmx/submitCallRecordHandle").toString();
        String postParam =  pokeRequestServe.spellPrams(params);

        return pokeRequestServe.transPost(url.toString(), "电话解决记录", "applyBorrowTool", postParam);
    }

    @Override
    public ResponseWithData<?> getUserContInfo(String mobile) {
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
//        url.append("getUserEqInfoByCustName.asmx/getUserEqInfoByCustNameHandle");
        url.append("getusercontinfo.asmx/getUserContHandle");
        StringBuffer postParam = new StringBuffer("mobile=").append(mobile);

        return pokeRequestServe.transPost(url.toString(), "手机号获取联系人客户信息接口", "getUserContHandle", postParam.toString());
    }

    @Override
    public ResponseWithData<?> getUserEqInfoByCustName(String custName) {
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("getUserEqInfoByCustName.asmx/getUserEqInfoByCustNameHandle");
        StringBuffer postParam = new StringBuffer("CustName=").append(custName);

        return pokeRequestServe.transPost(url.toString(), "客户名称获取客户仪器信息接口", "getUserEqInfoByCustNameHandle", postParam.toString());
    }

    @Override
    public ResponseWithData<?> getUserEqInfoBySerial(String serial) {
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);

        //来回变，又用下边的了
        //url.append("getEngineerByName.asmx/getEngineerByNameHandle");
        url.append("getUserEqInfoBySerial.asmx/getUserEqInfoBySerialHandle");
        StringBuffer postParam = new StringBuffer("Serial=").append(serial);

        return pokeRequestServe.transPost(url.toString(), "序列号获取客户仪器信息接口", "getUserEqInfoBySerial", postParam.toString());
    }
}
